interface Pagination {
  current: number
  pageSize: number
  total: number
}
interface PaginationData<D = any> {
  list: D[]
  pagination: Pagination
}
export function usePaginationData<D = any>() {
  const list = ref<D[]>([])
  const hasNext = ref(true)
  const total = ref<number>(0)
  function evaluate(paginationData: PaginationData<D>) {
    const { pagination, list: items } = paginationData
    list.value = pagination.current === 1 ? items : list.value.concat(items as any)
    hasNext.value = items.length >= pagination.pageSize
    total.value = pagination.total
  }
  function reset(clearList = true) {
    if (clearList) {
      list.value = []
    }
    hasNext.value = true
  }
  return {
    total,
    list,
    hasNext,
    evaluate,
    reset
  }
}